<div class="x_panel">
  <div class="x_content row">
    <div class="col-xs-12">
      <form class="form-horizontal form-label-left" action="{$actionUrl}" method="post" enctype="multipart/form-data">
        <div class="form-group">
          <label class="control-label col-md-2 col-sm-4 col-xs-12">课程名称：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <input class="form-control col-md-3 col-xs-12" required="required" type="text" name="form[course_name]" value="{$course.course_name}">
          </div>
          {if $course.course_type!=7}
          <label class="control-label col-md-2 col-sm-4 col-xs-12">课程价格：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <input class="form-control col-md-3 col-xs-12" required="required" type="text" name="form[course_price]" value="{$course.course_price}">
          </div>
          {/if}

          <label class="control-label col-md-2 col-sm-4 col-xs-12">封面图片：</label>
          <div class="checkbox col-md-10 col-sm-12 com-xs-12">
            {if $course_pic}<img style="width:100px;height:100px;" src="{$course_pic}"/>{/if}
            <input type="file" name="course_pic">
          </div>

          <label class="control-label col-md-2 col-sm-4 col-xs-12">课程简介：</label>
          <div class="col-md-10 col-sm-9 col-xs-12">
              <textarea rows="20" id="J_detail" name="form[course_desc]">
                {$course.course_desc}
              </textarea>
          </div>

          {if $course.course_type==2}
          <label class="control-label col-md-2 col-sm-4 col-xs-12">扩展分类：</label>
          <div class="checkbox col-md-8 col-sm-8 col-xs-12">
            <select class="form-control" name="form[extend_type]">
              <option value="1" {if $course.extend_type==1}selected{/if}>YCT1</option>
              <option value="2" {if $course.extend_type==2}selected{/if}>YCT2</option>
              <option value="3" {if $course.extend_type==3}selected{/if}>YCT3</option>
            </select>
          </div>
          {elseif $course.course_type==3}
          <label class="control-label col-md-2 col-sm-4 col-xs-12">扩展分类：</label>
          <div class="checkbox col-md-8 col-sm-8 col-xs-12">
            <select class="form-control" name="form[extend_type]">
              <option value="4" {if $course.extend_type==4}selected{/if}>HSK2</option>
              <option value="5" {if $course.extend_type==5}selected{/if}>HSK3</option>
              <option value="6" {if $course.extend_type==6}selected{/if}>HSK4</option>
            </select>
          </div>
          {elseif $course.course_type==5}
          <label class="control-label col-md-2 col-sm-4 col-xs-12">扩展分类：</label>
          <div class="checkbox col-md-8 col-sm-8 col-xs-12">
            <select class="form-control" name="form[extend_type]">
              <option value="7" {if $course.extend_type==7}selected{/if}>少儿西语1</option>
              <option value="8" {if $course.extend_type==8}selected{/if}>少儿西语2</option>
              <option value="9" {if $course.extend_type==9}selected{/if}>西语数学</option>
            </select>
          </div>
          {elseif $course.course_type==6}
          <label class="control-label col-md-2 col-sm-4 col-xs-12">扩展分类：</label>
          <div class="checkbox col-md-8 col-sm-8 col-xs-12">
            <select class="form-control" name="form[extend_type]">
              <option value="10" {if $course.extend_type==10}selected{/if}>A1</option>
              <option value="11" {if $course.extend_type==11}selected{/if}>A2</option>
              <option value="12" {if $course.extend_type==12}selected{/if}>B1</option>
            </select>
          </div>
          {/if}

        </div>
        <div class="col-md-3 col-sm-12 col-xs-12 col-md-offset-4 col-sm-offset-4">
          <input type="hidden" name="course_id" value="{$course.course_id}">
          <button class="btn btn-primary" type="submit">更新</button>
        </div>
      </form>
    </div>
  </div>
</div>


<div class="x_panel">
  <div class="x_content" style="display: block;">
    <div class="nav navbar-right panel_toolbox">
      <button id="add-chapter" class="fa fa-plus"> 添加</button>
    </div>
    <br><br>
    <!--表格主体内容-->
    <div class="cont">
      <table class="table table-bordered table-striped">
        <thead>
        <tr>
          <th width="100px">序号</th>
          <th>章节名称</th>
          <th>章节排序</th>
          <th>创建时间</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $chapter.lists as $chapteritem}
        <tr>
          <td>{$chapteritem.chapter_id}</td>
          <td>{$chapteritem.chapter_name}</td>
          <td>{$chapteritem.chapter_order}</td>
          <td>{$chapteritem.add_time}</td>
          <td>
            <div class="x_content">
              <button data-id="{$chapteritem.chapter_id}" class="btn btn-primary btn-xs edit-chapter">编辑</button>
              <button class="btn btn-danger btn-xs" data-toggle="dropdown">删除
                <i class="icon-angle-down"></i></button>
              <ul class="dropdown-menu">
                <li><a href="{eval U(['course/delete-chapter','chapter_id'=>$chapteritem.chapter_id])}">确定</a></li>
                <li><a href="javascript:;">取消</a></li>
              </ul>
            </div>
          </td>
        </tr>
        {/foreach}
        </tbody>
      </table>
      {Yii::$app->view->render('/com/pager.php',['pager'=>$chapter['pager']])}
    </div>
  </div>
</div>

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="detail-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header" style="border:none">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel1">添加章节</h4>
      </div>
      <form action="/course/add-chapter.html" method="post" enctype="multipart/form-data">
      <div class="modal-body">
        <div class="loaders">

          <div class="ball-spin-fade-loader">
            章节名称：<input name="form[chapter_name]" type="text" value="" />
            <br>
            章节编号：<input name="form[chapter_no]" type="text" value="" />
            <br>
            章节视频封面：<input type="file" name="chapter_pic">
            <br>
            章节视频：<input type="file" name="chapter_video">
            <br>
            试看视频：<input type="file" name="chapter_test_video">
            <br>
            视频时长：<input name="form[video_time]" type="text" value="" />
            <br>
            试题模板：
            <select  class="form-control" name="form[paper_id]">
            <option value="0">请选择</option>
              {foreach $paper AS $value}
              <option value="{$value.paper_id}">{$value.paper_name}</option>
              {/foreach}
            </select>
            <br>
            章节排序：<input name="form[chapter_order]" type="text" value="" />
          </div>

        </div>
        <div id="modal-dyn1"></div>
      </div>
      <div class="modal-footer" style="border:none;">
        <input type="hidden" name="form[course_id]" value="{$course.course_id}">
        <button type="submit" class="copy btn btn-secondary" data-paper="" data-test="">提交</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
      </div>
      </form>
    </div>
  </div>
</div>

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="detail-modal1">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header" style="border:none">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel2">编辑章节</h4>
      </div>
      <form action="/course/edit-chapter.html" method="post" enctype="multipart/form-data">
        <div class="modal-body">
          <div class="loaders">

            <div class="ball-spin-fade-loader">
              章节名称：<input id="chapter_name" name="form[chapter_name]" type="text" value="" />
              <br>
              章节编号：<input id="chapter_no" name="form[chapter_no]" type="text" value="" />
              <br>
              章节视频封面：<img id="chapter_pic" style="width:100px;height:100px;" src=""/><input type="file" name="chapter_pic">
              <br>
              章节视频：
              <span id="chapter_video"></span>
              <input type="file" name="chapter_video">
              <br>
              试看视频：
              <span id="chapter_test_video"></span>
              <input type="file" name="chapter_test_video">
              <br>
              视频时长：<input id="video_time" name="form[video_time]" type="text" value="" />
              <br>
              试题模板：
              <select id="paper_id"  class="form-control" name="form[paper_id]">
                <option value="0">请选择</option>
                {foreach $paper AS $value}
                <option value="{$value.paper_id}">{$value.paper_name}</option>
                {/foreach}
              </select>
              <br>
              章节排序：<input id="chapter_order" name="form[chapter_order]" type="text" value="" />
            </div>

          </div>
          <div id="modal-dyn2"></div>
        </div>
        <div class="modal-footer" style="border:none;">
          <input id="chapterid" type="hidden" name="chapter_id" value="">
          <button type="submit" class="copy btn btn-secondary" data-paper="" data-test="">提交</button>
          <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
        </div>
      </form>
    </div>
  </div>
</div>

<script src="{$theme}/js/source/ueditor/ueditor.config.js"></script>
<script src="{$theme}/js/source/ueditor/ueditor.all.js"></script>
<script src="{$theme}/js/source/ueditor/lang/zh-cn/zh-cn.js"></script>
<script src="{$theme}/js/source/layer/layer.js"></script>
<script src="{$theme}/libs/js/select/select2.full.js"></script>
<script>
    window.UEDITOR_CONFIG.initialFrameHeight = 320;

    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
            return '/index/upload.html';
        } else if(action == 'uploadvideo')
        {
            return '/index/upload-video.html';
        }
        else
        {
            return this._bkGetActionUrl.call(this, action);
        }
    }
    var detailUe = UE.getEditor('J_detail');


    $("#add-chapter").click(function () {
        $('#detail-modal').modal('show');
    })

    $(".edit-chapter").click(function () {
        var chapter_id = $(this).attr('data-id');
        $('#chapterid').val(chapter_id);
        var url = "{['course/get-chapter']|U}";
        $.post(url, 'chapter_id='+chapter_id, function (data) {
            $('#chapter_name').val(data.chapter_name);
            $('#chapter_no').val(data.chapter_no);
            $('#chapter_pic').attr('src',data.chapter_pic);
            $('#chapter_video').text(data.chapter_video);
            $('#chapter_test_video').text(data.chapter_test_video);
            $('#video_time').val(data.video_time);
            $('#paper_id').val(data.paper_id);
            $('#chapter_order').val(data.chapter_order);
        },'json');
        $('#detail-modal1').modal('show');
    })
</script>
